package com.tour.service.impl;

import static org.hamcrest.CoreMatchers.nullValue;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.tour.common.ServerResponse;
import com.tour.dao.OrderMapper;
import com.tour.pojo.Order;
import com.tour.pojo.TrevalProject;
import com.tour.service.IOrderService;

@Service
public class OrderServiceImpl implements IOrderService{
	
	@Resource
	private OrderMapper orderMapper;

	@Override
	public ServerResponse deleteByPrimaryKey(Long orderId) {
		int result =orderMapper.deleteByPrimaryKey(orderId);
		if(result>0){
			return ServerResponse.createBySuccessMessage("删除成功");
		}
		return ServerResponse.createBySuccessMessage("删除失败");
	}

	@Override
	public ServerResponse<Order> insertSelective(Order record) {
		 int result = orderMapper.insertSelective(record);
			if(result>0){
				return ServerResponse.createBySuccessMessage("添加成功");
			}
			return ServerResponse.createBySuccessMessage("添加失败");
	}

	
	@Override
	public ServerResponse selectByUserId(Integer userId, Integer pageIndex, Integer pageSize) {
		PageHelper.startPage(pageIndex, pageSize);
		List<Order> orderList = orderMapper.selectByUserId(userId, pageIndex, pageSize);
		if(orderList.size()>0){
			return ServerResponse.createBySuccess("获取订单列表成功", orderList);
		}else{
			return ServerResponse.createBySuccess("您还没有订单", null);
		}
	}

	@Override
	public ServerResponse<Order> updateByPrimaryKeySelective(Order record) {
		 int result = orderMapper.updateByPrimaryKeySelective(record);
			if(result>0){
				return ServerResponse.createBySuccessMessage("修改成功");
			}
			return ServerResponse.createBySuccessMessage("修改失败");
	}

	
	@Override
	public ServerResponse getOrderCount(Integer userId) {
		
		return ServerResponse.createBySuccess(orderMapper.getOrderCount(userId));
	}



}
